from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-08 14:12:54.104879
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 08, Jul, 2022
Time: 14:13:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7267
Nobs: 711.000 HQIC: -50.0815
Log likelihood: 8893.57 FPE: 1.42203e-22
AIC: -50.3048 Det(Omega_mle): 1.25405e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298215 0.057399 5.195 0.000
L1.Burgenland 0.104571 0.037678 2.775 0.006
L1.Kärnten -0.109509 0.019978 -5.482 0.000
L1.Niederösterreich 0.211501 0.078782 2.685 0.007
L1.Oberösterreich 0.105766 0.077096 1.372 0.170
L1.Salzburg 0.257065 0.040333 6.373 0.000
L1.Steiermark 0.044190 0.052531 0.841 0.400
L1.Tirol 0.109761 0.042651 2.573 0.010
L1.Vorarlberg -0.061320 0.036879 -1.663 0.096
L1.Wien 0.045176 0.068065 0.664 0.507
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047473 0.120160 0.395 0.693
L1.Burgenland -0.034203 0.078875 -0.434 0.665
L1.Kärnten 0.041169 0.041821 0.984 0.325
L1.Niederösterreich -0.166787 0.164924 -1.011 0.312
L1.Oberösterreich 0.422608 0.161394 2.618 0.009
L1.Salzburg 0.288337 0.084435 3.415 0.001
L1.Steiermark 0.100222 0.109970 0.911 0.362
L1.Tirol 0.318714 0.089285 3.570 0.000
L1.Vorarlberg 0.027051 0.077203 0.350 0.726
L1.Wien -0.037234 0.142489 -0.261 0.794
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187690 0.029362 6.392 0.000
L1.Burgenland 0.089481 0.019274 4.643 0.000
L1.Kärnten -0.007934 0.010219 -0.776 0.438
L1.Niederösterreich 0.265651 0.040300 6.592 0.000
L1.Oberösterreich 0.137669 0.039438 3.491 0.000
L1.Salzburg 0.045948 0.020632 2.227 0.026
L1.Steiermark 0.019737 0.026872 0.734 0.463
L1.Tirol 0.091372 0.021818 4.188 0.000
L1.Vorarlberg 0.057279 0.018865 3.036 0.002
L1.Wien 0.114310 0.034818 3.283 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111792 0.029868 3.743 0.000
L1.Burgenland 0.045184 0.019606 2.305 0.021
L1.Kärnten -0.013770 0.010395 -1.325 0.185
L1.Niederösterreich 0.191390 0.040994 4.669 0.000
L1.Oberösterreich 0.303339 0.040117 7.561 0.000
L1.Salzburg 0.108354 0.020988 5.163 0.000
L1.Steiermark 0.104692 0.027335 3.830 0.000
L1.Tirol 0.104082 0.022193 4.690 0.000
L1.Vorarlberg 0.066558 0.019190 3.468 0.001
L1.Wien -0.022236 0.035418 -0.628 0.530
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134361 0.054467 2.467 0.014
L1.Burgenland -0.051949 0.035753 -1.453 0.146
L1.Kärnten -0.044392 0.018957 -2.342 0.019
L1.Niederösterreich 0.156866 0.074757 2.098 0.036
L1.Oberösterreich 0.139999 0.073157 1.914 0.056
L1.Salzburg 0.286874 0.038273 7.495 0.000
L1.Steiermark 0.047240 0.049848 0.948 0.343
L1.Tirol 0.167228 0.040472 4.132 0.000
L1.Vorarlberg 0.091757 0.034995 2.622 0.009
L1.Wien 0.074383 0.064588 1.152 0.249
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055103 0.043333 1.272 0.204
L1.Burgenland 0.037998 0.028444 1.336 0.182
L1.Kärnten 0.050953 0.015082 3.378 0.001
L1.Niederösterreich 0.217286 0.059476 3.653 0.000
L1.Oberösterreich 0.295075 0.058203 5.070 0.000
L1.Salzburg 0.048017 0.030450 1.577 0.115
L1.Steiermark 0.001467 0.039658 0.037 0.970
L1.Tirol 0.141302 0.032199 4.388 0.000
L1.Vorarlberg 0.072699 0.027842 2.611 0.009
L1.Wien 0.081005 0.051386 1.576 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174742 0.051819 3.372 0.001
L1.Burgenland -0.002960 0.034014 -0.087 0.931
L1.Kärnten -0.063005 0.018035 -3.493 0.000
L1.Niederösterreich -0.080547 0.071123 -1.133 0.257
L1.Oberösterreich 0.194201 0.069601 2.790 0.005
L1.Salzburg 0.056668 0.036412 1.556 0.120
L1.Steiermark 0.235503 0.047424 4.966 0.000
L1.Tirol 0.497630 0.038504 12.924 0.000
L1.Vorarlberg 0.043319 0.033293 1.301 0.193
L1.Wien -0.053006 0.061448 -0.863 0.388
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170642 0.059147 2.885 0.004
L1.Burgenland -0.010382 0.038825 -0.267 0.789
L1.Kärnten 0.063558 0.020586 3.087 0.002
L1.Niederösterreich 0.206787 0.081181 2.547 0.011
L1.Oberösterreich -0.074969 0.079444 -0.944 0.345
L1.Salzburg 0.213188 0.041562 5.129 0.000
L1.Steiermark 0.125478 0.054131 2.318 0.020
L1.Tirol 0.068849 0.043949 1.567 0.117
L1.Vorarlberg 0.118176 0.038002 3.110 0.002
L1.Wien 0.121145 0.070138 1.727 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362483 0.034236 10.588 0.000
L1.Burgenland 0.006271 0.022473 0.279 0.780
L1.Kärnten -0.023516 0.011916 -1.973 0.048
L1.Niederösterreich 0.217866 0.046990 4.636 0.000
L1.Oberösterreich 0.202733 0.045984 4.409 0.000
L1.Salzburg 0.043199 0.024057 1.796 0.073
L1.Steiermark -0.015353 0.031333 -0.490 0.624
L1.Tirol 0.105038 0.025439 4.129 0.000
L1.Vorarlberg 0.069876 0.021997 3.177 0.001
L1.Wien 0.033601 0.040598 0.828 0.408
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037482 0.138550 0.194740 0.155733 0.115311 0.102830 0.057483 0.217289
Kärnten 0.037482 1.000000 -0.015661 0.134116 0.055982 0.095059 0.435734 -0.053557 0.093621
Niederösterreich 0.138550 -0.015661 1.000000 0.334727 0.140848 0.293270 0.092177 0.175350 0.312973
Oberösterreich 0.194740 0.134116 0.334727 1.000000 0.227186 0.325087 0.176410 0.164372 0.262009
Salzburg 0.155733 0.055982 0.140848 0.227186 1.000000 0.138115 0.116824 0.138317 0.129040
Steiermark 0.115311 0.095059 0.293270 0.325087 0.138115 1.000000 0.145270 0.131639 0.070648
Tirol 0.102830 0.435734 0.092177 0.176410 0.116824 0.145270 1.000000 0.110683 0.142402
Vorarlberg 0.057483 -0.053557 0.175350 0.164372 0.138317 0.131639 0.110683 1.000000 -0.001628
Wien 0.217289 0.093621 0.312973 0.262009 0.129040 0.070648 0.142402 -0.001628 1.000000